package com.huage_09;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huage_09.domain.User;

import java.util.ArrayList;
import java.util.Date;

public class ListToJson {
    public static void main(String[] args) throws JsonProcessingException {
        User user1 = new User("张三", 23, "男");
        user1.setDate(new Date());
        User user2 = new User("李四", 24, "女");
        user2.setDate(new Date());
        User user3 = new User("王五", 25, "男");
        user3.setDate(new Date());

        ArrayList<User> userList = new ArrayList<User>();
        userList.add(user1);
        userList.add(user2);
        userList.add(user3);

        ObjectMapper obj = new ObjectMapper();
        String json = obj.writeValueAsString(userList);
        System.out.println(json);
    }
}
